package pl.perseus.action;

import java.util.HashMap;

import lombok.Getter;
import lombok.Setter;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;

import pl.perseus.model.Passlist;
import pl.perseus.service.passlist.IPassListService;
import pl.perseus.service.user.IUserService;

public class GetConfirmationAction extends BaseAction {

	@Autowired
	IPassListService passListService;
	
	@Autowired
	IUserService userService;
	
	@Getter
	@Setter
	String conf;
	
	@Override
	public String execute() {
		result = new HashMap<String, Object>();
		Passlist pass = passListService.getFirstUnusedPassListForUser(userService.selectUserByLogin(getCurrentUserLogin()));
		
		result.put("pass", pass);
		result.put("conf", DigestUtils.md5Hex(conf).equals(pass.getPass().trim()));
		
		return SUCCESS;
	}

}
